<%--
  Created by IntelliJ IDEA.
  User: set_free
  Date: 003
  Time: 8:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="utils.FileUtil,java.util.List"  pageEncoding="utf-8"%>
<%@ page import="java.io.File" %>
<%@ page import="utils.UrlUtil" %>

<html>
  <head>
    <title>测试</title>
    <script>
      function turnPage(url){
        if(url){
          window.location.href = url + "&rn=" + Math.random();
        }
      }
    </script>
  </head>
  <body>
  测试题
  <div>
  <%
      String filePath = request.getServletContext().getRealPath("/exame_docs/");
      File docFile = new File(filePath);
      File[] files = docFile.listFiles();
      FileUtil.sortFileName(files);
      for (int i = 0; i < files.length; i++) {
          File fileTemp = files[i];
          String fileNameTemp = fileTemp.getName();
          fileNameTemp = UrlUtil.getURLEncoderString(fileNameTemp);
          %>
        <p><%=(i+1)%>.<a href="javascript:void(0);" onclick="turnPage('<%=request.getContextPath()%>/DownloadServlet?destPath=exame_docs&downLoad=1&fileName=<%=fileNameTemp%>');" target="_blank"><%=fileNameTemp%></a></p>
        <%
      }
  %>
  </div>
  <%--<div>
    <p><a href="javascript:void(0);" onclick="turnPage('<%=request.getContextPath()%>/DownloadServlet?fileName=20200704JavaTest.docx');" target="_blank">20200704JavaTest.docx</a></p>
      <p><a href="javascript:void(0);" onclick="turnPage('<%=request.getContextPath()%>/DownloadServlet?fileName=20200711Java_Collection_test.docx');" target="_blank">20200711Java_Collection_test.docx</a></p>
    <p><a href="javascript:void(0);" onclick="turnPage('<%=request.getContextPath()%>/DownloadServlet?fileName=20200704Java_mysql_Test.docx');" target="_blank">20200704Java_mysql_Test.docx</a></p>
    <p><a href="javascript:void(0);" onclick="turnPage('<%=request.getContextPath()%>/DownloadServlet?fileName=20200718_Exception_Generic.docx');" target="_blank">20200718_Exception_Generic.docx</a></p>
  </div>--%>
  <hr/>
  测试题上传
  <div>
    <form method="post" action="<%=request.getContextPath()%>/UploadServlet" enctype="multipart/form-data">
      选择文件:
      <input type="file" name="uploadFile" />
      <br/><br/>
      <input type="submit" value="上传" />
    </form>
    <h2>${message}</h2>
  </div>
  <hr/>
  文件列表：
  <div>
    <%
      List<File> fileList = FileUtil.getallfile("/upload");
      for (int i = 0; i < fileList.size(); i++) {
          String fileNameTemp = fileList.get(i).getName();
        fileNameTemp = UrlUtil.getURLEncoderString(fileNameTemp);
        %>
    <%=i %>.<%=fileList.get(i).getName() %>&nbsp;&nbsp;
    <a href="javascript:void(0);" onclick="turnPage('<%=request.getContextPath()%>/DownloadServlet?downLoad=1&destPath=upload&fileName=<%=fileNameTemp %>');" target="_blank">下载</a>
    <br/>
    <%
          if(i !=0  && i % 5 == 0){
              %>
      <br/>
      <%
          }
      }
    %>
  </div>
  </body>
</html>
